#ifndef BWIDGET_H
#define BWIDGET_H

#include <QWidget>
#include <QMainWindow>
#include <QGroupBox>
#include <QPushButton>
#include <QSlider>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QComboBox>
#include <QDebug>
#include <QScreen>

// 开发环境参数
namespace DevEnv {
constexpr double L_DPI_X = 96.0;
constexpr double L_DPI_Y = 96.0;

constexpr double A_WIDTH = 1920.0;
constexpr double A_HEIGHT = 1044.0;
// 宽度计算值
constexpr double W_VALUE = L_DPI_X * A_WIDTH;
// 高度计算值
constexpr double H_VALUE = L_DPI_Y * A_HEIGHT;

constexpr int CTRL_FIX_WIDTH = 80;
constexpr int CTRL_FIX_HEIGHT = 20;

}




class BWidget : public QWidget
{
    Q_OBJECT
public:
    explicit BWidget(QWidget *parent = nullptr);

public:
    double ratio() const;
    double wratio() const;
    double hratio() const;
    void resize(const QSize &s);
    void resize(int w, int h);
    void setFixedHeight(int h);
    void setFixedSize(const QSize &s);
    void setFixedSize(int w, int h);
    void setFixedWidth(int w);
    void setMaximumHeight(int maxh);
    void setMaximumSize(const QSize &s);
    void setMaximumSize(int maxw, int maxh);
    void setMaximumWidth(int maxw);
    void setMinimumHeight(int minh);
    void setMinimumSize(const QSize &s);
    void setMinimumSize(int minw, int minh);
    void setMinimumWidth(int minw);
private:
    const double w_ratio;
    const double h_ratio;
};

class BMainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit BMainWindow(QWidget *parent = nullptr);

public:
    double ratio() const;
    void resize(const QSize &s);
    void resize(int w, int h);
private:
    const double w_ratio;
    const double h_ratio;
};

class BGroupBox : public QGroupBox
{
    Q_OBJECT
public:
    explicit BGroupBox(QWidget *parent = nullptr);
    explicit BGroupBox(const QString &title, QWidget *parent = nullptr);

public:
    double ratio() const;
    void resize(const QSize &s);
    void resize(int w, int h);
    void setFixedHeight(int h);
    void setFixedSize(const QSize &s);
    void setFixedSize(int w, int h);
    void setFixedWidth(int w);
    void setMaximumHeight(int maxh);
    void setMaximumSize(const QSize &s);
    void setMaximumSize(int maxw, int maxh);
    void setMaximumWidth(int maxw);
    void setMinimumHeight(int minh);
    void setMinimumSize(const QSize &s);
    void setMinimumSize(int minw, int minh);
    void setMinimumWidth(int minw);
private:
    const double w_ratio;
    const double h_ratio;
};

class BPushButton : public QPushButton
{
    Q_OBJECT
public:
    explicit BPushButton(QWidget *parent = nullptr)
        : QPushButton{parent}
        , w_ratio{screen()->availableSize().width() / DevEnv::A_WIDTH}
        , h_ratio{screen()->availableSize().height() / DevEnv::A_HEIGHT}
    {
        setFixedHeight(DevEnv::CTRL_FIX_HEIGHT);
        setFixedWidth(DevEnv::CTRL_FIX_WIDTH);
    }
    explicit BPushButton(const QString &title, QWidget *parent = nullptr)
        : QPushButton{title, parent}
        , w_ratio{screen()->availableSize().width() / DevEnv::A_WIDTH}
        , h_ratio{screen()->availableSize().height() / DevEnv::A_HEIGHT}
    {
        setFixedHeight(DevEnv::CTRL_FIX_HEIGHT);
        setFixedWidth(DevEnv::CTRL_FIX_WIDTH);
    }
    void setFixedHeight(int h)
    {
        QWidget::setFixedHeight(h * h_ratio);
    }
    void setFixedWidth(int w)
    {
        QWidget::setFixedWidth(w * w_ratio);
    }
private:
    const double w_ratio;
    const double h_ratio;
};

class BSlider : public QSlider
{
    Q_OBJECT
public:
    explicit BSlider(QWidget *parent = nullptr)
        : QSlider{parent}
        , w_ratio{screen()->availableSize().width() / DevEnv::A_WIDTH}
        , h_ratio{screen()->availableSize().height() / DevEnv::A_HEIGHT}
    {
        setFixedHeight(200);
    }
    void setFixedWidth(int w)
    {
        QWidget::setFixedWidth(w * w_ratio);
    }
    void setFixedHeight(int h)
    {
        QWidget::setFixedHeight(h * h_ratio);
    }
private:
    const double w_ratio;
    const double h_ratio;
};

class BSpinBox : public QSpinBox
{
    Q_OBJECT
public:
    explicit BSpinBox(QWidget *parent = nullptr)
        : QSpinBox{parent}
        , w_ratio{screen()->availableSize().width() / DevEnv::A_WIDTH}
        , h_ratio{screen()->availableSize().height() / DevEnv::A_HEIGHT}
    {
        setFixedHeight(DevEnv::CTRL_FIX_HEIGHT);
        setFixedWidth(DevEnv::CTRL_FIX_WIDTH);
    }
    void setFixedWidth(int w)
    {
        QWidget::setFixedWidth(w * w_ratio);
    }
    void setFixedHeight(int h)
    {
        QWidget::setFixedHeight(h * h_ratio);
    }
private:
    const double w_ratio;
    const double h_ratio;
};

class BDoubleSpinBox : public QDoubleSpinBox
{
    Q_OBJECT
public:
    explicit BDoubleSpinBox(QWidget *parent = nullptr)
        : QDoubleSpinBox{parent}
        , w_ratio{screen()->availableSize().width() / DevEnv::A_WIDTH}
        , h_ratio{screen()->availableSize().height() / DevEnv::A_HEIGHT}
    {
        setFixedHeight(DevEnv::CTRL_FIX_HEIGHT);
        setFixedWidth(DevEnv::CTRL_FIX_WIDTH);
    }
    void setFixedWidth(int w)
    {
        QWidget::setFixedWidth(w * w_ratio);
    }
    void setFixedHeight(int h)
    {
        QWidget::setFixedHeight(h * h_ratio);
    }
private:
    const double w_ratio;
    const double h_ratio;
};

class BComboBox : public QComboBox
{
    Q_OBJECT
public:
    explicit BComboBox(QWidget *parent = nullptr)
        : QComboBox{parent}
        , w_ratio{screen()->availableSize().width() / DevEnv::A_WIDTH}
        , h_ratio{screen()->availableSize().height() / DevEnv::A_HEIGHT}
    {
        setFixedHeight(DevEnv::CTRL_FIX_HEIGHT);
        setFixedWidth(DevEnv::CTRL_FIX_WIDTH);
    }
    void setFixedWidth(int w)
    {
        QWidget::setFixedWidth(w * w_ratio);
    }
    void setFixedHeight(int h)
    {
        QWidget::setFixedHeight(h * h_ratio);
    }
private:
    const double w_ratio;
    const double h_ratio;
};

#endif // BWIDGET_H
